﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TimeSheet.UI.Views
{
    /// <summary>
    /// Class to manage a project row
    /// </summary>
    public class WeekProjectView : INotifyPropertyChanged
    {
        #region EVENTS

        /// <summary>
        /// Raise the Property Event Changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region DECLARATIONS

        private double _width = 0;
        private string _monday = string.Empty;
        private string _tuesday = string.Empty;
        private string _wednesday = string.Empty;
        private string _thursday = string.Empty;
        private string _friday = string.Empty;
        private string _saturday = string.Empty;
        private string _sunday = string.Empty;

        #endregion

        #region CONSTRUCTORS

        /// <summary>
        /// Initializes a new instance of WeekView
        /// </summary>
        public WeekProjectView()
        {
            
        }

        #endregion

        #region PROPERTIES

        /// <summary>
        /// Sets or gets the Project Name
        /// </summary>
        public string Project { get; set; }

        /// <summary>
        /// Sets or gets the Monday value
        /// </summary>
        public string Monday
        {
            get
            {
                return _monday;
            }
            set
            {
                _monday = GetFormattedTime(value);
                OnPropertyChanged("Monday");
            }
        }

        /// <summary>
        /// Sets or gets the Tuesday value
        /// </summary>
        public string Tuesday
        {
            get
            {
                return _tuesday;
            }
            set
            {
                _tuesday = GetFormattedTime(value);
                OnPropertyChanged("Tuesday");
            }
        }

        /// <summary>
        /// Sets or gets the Wednesday value
        /// </summary>
        public string Wednesday
        {
            get
            {
                return _wednesday;
            }
            set
            {
                _wednesday = GetFormattedTime(value);
                OnPropertyChanged("Wednesday");
            }
        }

        /// <summary>
        /// Sets or gets the Thursday value
        /// </summary>
        public string Thursday
        {
            get
            {
                return _thursday;
            }
            set
            {
                _thursday = GetFormattedTime(value);
                OnPropertyChanged("Thursday");
            }
        }

        /// <summary>
        /// Sets or gets the Friday value
        /// </summary>
        public string Friday
        {
            get
            {
                return _friday;
            }
            set
            {
                _friday = GetFormattedTime(value);
                OnPropertyChanged("Friday");
            }
        }

        /// <summary>
        /// Sets or gets the Saturday value
        /// </summary>
        public string Saturday
        {
            get
            {
                return _saturday;
            }
            set
            {
                _saturday = GetFormattedTime(value);
                OnPropertyChanged("Saturday");
            }
        }

        /// <summary>
        /// Sets or gets the Sunday value
        /// </summary>
        public string Sunday
        {
            get
            {
                return _sunday;
            }
            set
            {
                _sunday = GetFormattedTime(value);
                OnPropertyChanged("Sunday");
            }
        }

        /// <summary>
        /// Sets or gets the Project Label width
        /// </summary>
        public double Width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
                OnPropertyChanged("Width");
            }
        }

        #endregion

        #region PRIVATES

        /// <summary>
        /// Raise the PropertyChanged event
        /// </summary>
        /// <param name="propertyName"></param>
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Get the value time correctly formatted (HH:MM)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private string GetFormattedTime(string value)
        { 
            TimeSpan? time = value.ToTime();

            if (time == null)
                return string.Empty;
            else
                return time.ToHoursMinutes();
        }

        #endregion

    }
}
